package com.zkq.graduate.service.impl;

import com.zkq.graduate.mapper.SystemTimeMapper;
import com.zkq.graduate.pojo.SystemTime;
import com.zkq.graduate.service.SystemTimeService;
import com.zkq.graduate.util.LocalDateTimeUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * @Author zhangkaiqiang
 * @Date 2019/12/24  16:47
 * @Description TODO
 */
@Service("systemTimeService")
public class SystemTimeServiceImpl implements SystemTimeService{


	@Resource
	private SystemTimeMapper systemTimeMapper;

	@Override
	public boolean insertOneRecord(SystemTime time) {
		if(time!=null){
			time.setSetTime(LocalDateTimeUtil.getStringNow());
			return systemTimeMapper.insertOneRecord(time)==1;
		}
		return false;
	}

	@Override
	public List<SystemTime> findAll() {
		List<SystemTime> list=systemTimeMapper.findAll();
		if(CollectionUtils.isEmpty(list)){
			return new ArrayList<>();
		}
		return list;
	}

	@Override
	public Optional<SystemTime> findByName(String timeName) {
		return Optional.ofNullable(systemTimeMapper.findByName(timeName));
	}

	@Override
	public Optional<SystemTime> findById(int id) {
		return Optional.ofNullable(systemTimeMapper.findById(id));
	}

	@Override
	public boolean updateById(SystemTime systemTime) {
		if(systemTime!=null){
			return systemTimeMapper.updateById(systemTime)==1;
		}
		return false;
	}

	@Override
	public boolean deleteByIds(String[] id) {
		if(id!=null && id.length>0){
			return systemTimeMapper.deleteByIds(id)==1;
		}
		return false;
	}
}
